//
//  DetailModel.swift
//  Pods
//
//  Created by eme on 2017/4/11.
//
//

import UIKit
import SwiftyJSON
import NetWorkCore
import ModelProtocol

class DetailModel:ModelProtocol{
    
    // MARK: Declaration for string constants to be used to decode and also serialize.
    internal let kDetailAgmobileKey: String = "agmobile"
    internal let kDetailShippingdateKey: String = "shippingdate"
    internal let kDetailPsfnameKey: String = "psfname"
    internal let kDetailAdressKey: String = "adress"
    internal let kDetailOrderstatusKey: String = "orderstatus"
    internal let kDetailCommentKey: String = "comment"
    internal let kDetailPayidKey: String = "payid"
    internal let kDetailPsfname2Key: String = "psfname2"
    internal let kDetailIsshowKey: String = "isshow"
    internal let kDetailRemarkKey: String = "remark"
    internal let kDetailProvinceKey: String = "province"
    internal let kDetailIsinvoiceKey: String = "isinvoice"
    internal let kDetailPeidKey: String = "peid"
    internal let kDetailBridKey: String = "brid"
    internal let kDetailInvoicenoKey: String = "invoiceno"
    internal let kDetailSendtypeKey: String = "sendtype"
    internal let kDetailZipcodeKey: String = "zipcode"
    internal let kDetailInvoicetitleKey: String = "invoicetitle"
    internal let kDetailAgcontactKey: String = "agcontact"
    internal let kDetailIssaleKey: String = "issale"
    internal let kDetailPaydateKey: String = "paydate"
    internal let kDetailAgtelphoneKey: String = "agtelphone"
    internal let kDetailFinishdateKey: String = "finishdate"
    internal let kDetailAreaKey: String = "area"
    internal let kDetailCellphoneKey: String = "cellphone"
    internal let kDetailDetaildateKey: String = "detaildate"
    internal let kDetailPostageKey: String = "postage"
    internal let kDetailTelphoneKey: String = "telphone"
    internal let kDetailBdnameKey: String = "bdname"
    internal let kDetailInvoiceflagKey: String = "invoiceflag"
    internal let kDetailPdidKey: String = "pdid"
    internal let kDetailPdnumKey: String = "pdnum"
    internal let kDetailImg1Key: String = "img1"
    internal let kDetailBdconmentKey: String = "bdconment"
    internal let kDetailDetailidKey: String = "detailid"
    internal let kDetailSkuidKey: String = "skuid"
    internal let kDetailOrderidKey: String = "orderid"
    internal let kDetailDetailstatusKey: String = "detailstatus"
    internal let kDetailShpriceKey: String = "shprice"
    internal let kDetailDetailrnumberKey: String = "detailrnumber"
    internal let kDetailCityKey: String = "city"
    internal let kDetailPdnameKey: String = "pdname"
    internal let kDetailIsevaluateKey: String = "isevaluate"
    internal let kDetailUnderdateKey: String = "underdate"
    internal let kDetailBdidKey: String = "bdid"
    internal let kDetailSpidKey: String = "spid"
    internal let kDetailDetailtotalKey: String = "detailtotal"
    internal let kDetailInvoiceplaceKey: String = "invoiceplace"
    internal let kDetailPsvalueKey: String = "psvalue"
    internal let kDetailPdunitKey: String = "pdunit"
    internal let kDetailSelfidKey: String = "selfid"
    internal let kDetailOrderamountKey: String = "orderamount"
    internal let kDetailAgidKey: String = "agid"
    internal let kDetailPsvalue2Key: String = "psvalue2"
    internal let kDetailPdtypeKey: String = "pdtype"
    internal let kDetailRecipientsKey: String = "recipients"
    
    
    // MARK: 属性
    var agmobile: String
    var shippingdate: String
    var psfname: String
    var adress: String
    var orderstatus: String
    var comment: String
    var payid: String
    var psfname2: String
    var isshow: String
    var remark: String
    var province: String
    var isinvoice: String
    var peid: String
    var brid: String
    var invoiceno: String
    var sendtype: String
    var zipcode: String
    var invoicetitle: String
    var agcontact: String
    var issale: String
    var paydate: String
    var agtelphone: String
    var finishdate: String
    var area: String
    var cellphone: String
    var detaildate: String
    var postage: Int
    var telphone: String
    var bdname: String
    var invoiceflag: String
    var pdid: Int
    var pdnum: Int
    var img1: String
    var bdconment: String
    var detailid: String
    var skuid: Int
    var orderid: String
    var detailstatus: String
    var shprice: Int
    var detailrnumber: Int
    var city: String
    var pdname: String
    var isevaluate: String
    var underdate: String
    var bdid: String
    var spid: String
    var detailtotal: Int
    var invoiceplace: String
    var psvalue: String
    var pdunit: String
    var selfid: String
    var orderamount: Int
    var agid: String
    var psvalue2: String
    var pdtype: String
    var recipients: String
    var standard:String{
        get{
            if psfname == ""
            {
                return ""
            }
            else if psfname2 == ""
            {
                if psvalue != ""{
                    return self.psfname + ":" + self.psvalue
                }else{
                    return self.psfname
                }
                
            }
            else
            {
                if self.psvalue != "" && psvalue2 != ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue == "" && psvalue2 != ""{
                    
                    return self.psfname + ";" + self.psfname2 + ":" + self.psvalue2
                    
                }else if psvalue != "" && psvalue2 == ""{
                    
                    return self.psfname + ":" + self.psvalue + ";" + self.psfname2
                    
                }else{
                    return self.psfname + ";" + self.psfname2
                    
                }
            }
            
        }
        
    }
    
    
    // MARK: 实现MikerSwiftJSONAble 协议， 解析json数据
    required  init?(json: JSON) {
        agmobile = json[kDetailAgmobileKey].stringValue
        shippingdate = json[kDetailShippingdateKey].stringValue
        psfname = json[kDetailPsfnameKey].stringValue
        adress = json[kDetailAdressKey].stringValue
        orderstatus = json[kDetailOrderstatusKey].stringValue
        comment = json[kDetailCommentKey].stringValue
        payid = json[kDetailPayidKey].stringValue
        psfname2 = json[kDetailPsfname2Key].stringValue
        isshow = json[kDetailIsshowKey].stringValue
        remark = json[kDetailRemarkKey].stringValue
        province = json[kDetailProvinceKey].stringValue
        isinvoice = json[kDetailIsinvoiceKey].stringValue
        peid = json[kDetailPeidKey].stringValue
        brid = json[kDetailBridKey].stringValue
        invoiceno = json[kDetailInvoicenoKey].stringValue
        sendtype = json[kDetailSendtypeKey].stringValue
        zipcode = json[kDetailZipcodeKey].stringValue
        invoicetitle = json[kDetailInvoicetitleKey].stringValue
        agcontact = json[kDetailAgcontactKey].stringValue
        issale = json[kDetailIssaleKey].stringValue
        paydate = json[kDetailPaydateKey].stringValue
        agtelphone = json[kDetailAgtelphoneKey].stringValue
        finishdate = json[kDetailFinishdateKey].stringValue
        area = json[kDetailAreaKey].stringValue
        cellphone = json[kDetailCellphoneKey].stringValue
        detaildate = json[kDetailDetaildateKey].stringValue
        postage = json[kDetailPostageKey].intValue
        telphone = json[kDetailTelphoneKey].stringValue
        bdname = json[kDetailBdnameKey].stringValue
        invoiceflag = json[kDetailInvoiceflagKey].stringValue
        pdid = json[kDetailPdidKey].intValue
        pdnum = json[kDetailPdnumKey].intValue
        img1 = json[kDetailImg1Key].stringValue
        bdconment = json[kDetailBdconmentKey].stringValue
        detailid = json[kDetailDetailidKey].stringValue
        skuid = json[kDetailSkuidKey].intValue
        orderid = json[kDetailOrderidKey].stringValue
        detailstatus = json[kDetailDetailstatusKey].stringValue
        shprice = json[kDetailShpriceKey].intValue
        detailrnumber = json[kDetailDetailrnumberKey].intValue
        city = json[kDetailCityKey].stringValue
        pdname = json[kDetailPdnameKey].stringValue
        isevaluate = json[kDetailIsevaluateKey].stringValue
        underdate = json[kDetailUnderdateKey].stringValue
        bdid = json[kDetailBdidKey].stringValue
        spid = json[kDetailSpidKey].stringValue
        detailtotal = json[kDetailDetailtotalKey].intValue
        invoiceplace = json[kDetailInvoiceplaceKey].stringValue
        psvalue = json[kDetailPsvalueKey].stringValue
        pdunit = json[kDetailPdunitKey].stringValue
        selfid = json[kDetailSelfidKey].stringValue
        orderamount = json[kDetailOrderamountKey].intValue
        agid = json[kDetailAgidKey].stringValue
        psvalue2 = json[kDetailPsvalue2Key].stringValue
        pdtype = json[kDetailPdtypeKey].stringValue
        recipients = json[kDetailRecipientsKey].stringValue
        
    }
    
    
    /**
     Generates description of the object in the form of a NSDictionary.
     - returns: A Key value pair containing all valid values in the object.
     */
    internal func dictionaryRepresentation() -> [String : AnyObject ] {
        
        var dictionary: [String : AnyObject ] = [ : ]
        
        dictionary.updateValue(agmobile as AnyObject, forKey: kDetailAgmobileKey)
    
    
        dictionary.updateValue(shippingdate as AnyObject, forKey: kDetailShippingdateKey)
    
        dictionary.updateValue(psfname as AnyObject, forKey: kDetailPsfnameKey)
    
        dictionary.updateValue(adress as AnyObject, forKey: kDetailAdressKey)
    
        dictionary.updateValue(orderstatus as AnyObject, forKey: kDetailOrderstatusKey)
   
        dictionary.updateValue(comment as AnyObject, forKey: kDetailCommentKey)
    
        dictionary.updateValue(payid as AnyObject, forKey: kDetailPayidKey)
    
        dictionary.updateValue(psfname2 as AnyObject, forKey: kDetailPsfname2Key)
    
        dictionary.updateValue(isshow as AnyObject, forKey: kDetailIsshowKey)
    
        dictionary.updateValue(remark as AnyObject, forKey: kDetailRemarkKey)
    
        dictionary.updateValue(province as AnyObject, forKey: kDetailProvinceKey)
    
        dictionary.updateValue(isinvoice as AnyObject, forKey: kDetailIsinvoiceKey)
    
        dictionary.updateValue(peid as AnyObject, forKey: kDetailPeidKey)
    
        dictionary.updateValue(brid as AnyObject, forKey: kDetailBridKey)
    
        dictionary.updateValue(invoiceno as AnyObject, forKey: kDetailInvoicenoKey)
   
        dictionary.updateValue(sendtype as AnyObject, forKey: kDetailSendtypeKey)
    
        dictionary.updateValue(zipcode as AnyObject, forKey: kDetailZipcodeKey)
    
        dictionary.updateValue(invoicetitle as AnyObject, forKey: kDetailInvoicetitleKey)
    
        dictionary.updateValue(agcontact as AnyObject, forKey: kDetailAgcontactKey)
    
        dictionary.updateValue(issale as AnyObject, forKey: kDetailIssaleKey)
    
        dictionary.updateValue(paydate as AnyObject, forKey: kDetailPaydateKey)
    
        dictionary.updateValue(agtelphone as AnyObject, forKey: kDetailAgtelphoneKey)
    
        dictionary.updateValue(finishdate as AnyObject, forKey: kDetailFinishdateKey)
    
        dictionary.updateValue(area as AnyObject, forKey: kDetailAreaKey)
    
        dictionary.updateValue(cellphone as AnyObject, forKey: kDetailCellphoneKey)
    
        dictionary.updateValue(detaildate as AnyObject, forKey: kDetailDetaildateKey)
    
        dictionary.updateValue(postage as AnyObject, forKey: kDetailPostageKey)
    
        dictionary.updateValue(telphone as AnyObject, forKey: kDetailTelphoneKey)
    
        dictionary.updateValue(bdname as AnyObject, forKey: kDetailBdnameKey)
    
        dictionary.updateValue(invoiceflag as AnyObject, forKey: kDetailInvoiceflagKey)
    
        dictionary.updateValue(pdid as AnyObject, forKey: kDetailPdidKey)
    
        dictionary.updateValue(pdnum as AnyObject, forKey: kDetailPdnumKey)
    
        dictionary.updateValue(img1 as AnyObject, forKey: kDetailImg1Key)
    
        dictionary.updateValue(bdconment as AnyObject, forKey: kDetailBdconmentKey)
    
        dictionary.updateValue(detailid as AnyObject, forKey: kDetailDetailidKey)
        dictionary.updateValue(skuid as AnyObject, forKey: kDetailSkuidKey)
    
        dictionary.updateValue(orderid as AnyObject, forKey: kDetailOrderidKey)
    
        dictionary.updateValue(detailstatus as AnyObject, forKey: kDetailDetailstatusKey)
    
        dictionary.updateValue(shprice as AnyObject, forKey: kDetailShpriceKey)
    
        dictionary.updateValue(detailrnumber as AnyObject, forKey: kDetailDetailrnumberKey)
        dictionary.updateValue(city as AnyObject, forKey: kDetailCityKey)
    
        dictionary.updateValue(pdname as AnyObject, forKey: kDetailPdnameKey)
    
        dictionary.updateValue(isevaluate as AnyObject, forKey: kDetailIsevaluateKey)
    
        dictionary.updateValue(underdate as AnyObject, forKey: kDetailUnderdateKey)
    
        dictionary.updateValue(bdid as AnyObject, forKey: kDetailBdidKey)
    
        dictionary.updateValue(spid as AnyObject, forKey: kDetailSpidKey)
    
        dictionary.updateValue(detailtotal as AnyObject, forKey: kDetailDetailtotalKey)
    
        dictionary.updateValue(invoiceplace as AnyObject, forKey: kDetailInvoiceplaceKey)
    
        dictionary.updateValue(psvalue as AnyObject, forKey: kDetailPsvalueKey)
    
        dictionary.updateValue(pdunit as AnyObject, forKey: kDetailPdunitKey)
    
        dictionary.updateValue(selfid as AnyObject, forKey: kDetailSelfidKey)
    
        dictionary.updateValue(orderamount as AnyObject, forKey: kDetailOrderamountKey)
    
        dictionary.updateValue(agid as AnyObject, forKey: kDetailAgidKey)
    
        dictionary.updateValue(psvalue2 as AnyObject, forKey: kDetailPsvalue2Key)
        dictionary.updateValue(pdtype as AnyObject, forKey: kDetailPdtypeKey)
    
        dictionary.updateValue(recipients as AnyObject, forKey: kDetailRecipientsKey)

        
        return dictionary
    }
    
    
}
